package org.fuxia.im.listeners;

import javax.swing.SwingUtilities;

import org.fuxia.im.common.ClientConst;
import org.fuxia.im.common.ClientContext;
import org.fuxia.im.common.CommonDialog;
import org.fuxia.im.common.MyMessageDialog;
import org.fuxia.im.core.entries.ECResponse;
import org.fuxia.im.core.listeners.Listener;
import org.fuxia.im.gui.Main;

public class GroupOptionListener implements Listener {

	public void trigger(final Object param) {
		SwingUtilities.invokeLater(new Runnable() {
			
			public void run() {
				ECResponse resp = (ECResponse)param;
				if(resp.getStatusCode()!=null) {
					switch (resp.getStatusCode()) {
					case 300:
						String userCode = resp.get("user").toString() ;
						ClientContext.removeUserInGroup(userCode, resp.get("groupId").toString()) ;
						MyMessageDialog md = CommonDialog.createMessageNotifyWindow(resp.getResponseText());
						md.showDialog();
						break;
					case 500:
					case 600:
						ClientContext.getValue(ClientConst.MAIN_WINDOW, Main.class).deleteGroupNode(resp.get("groupId").toString());
						MyMessageDialog md1 = CommonDialog.createMessageNotifyWindow(resp.getResponseText());
						md1.showDialog();
						break;
					default:
						break;
					}
				}
				
			}
		});
	}

}
